// 引用 crypto-js 加密模块
import CryptoJS from 'crypto-js'

let desKey = "0123456789ABCDEF"    // 密钥
let desIv = "0123456789ABCDEF"    // 偏移量

// 处理字符串
const combineKey = (key)=>{
  return  CryptoJS.enc.Utf8.parse(key)
}

const option = (iv)=>{
    return {
        iv: combineKey(iv),
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Iso10126
    }
}

// 加密
export function tripleDesEncrypt(text) {
       const encrypted = CryptoJS.TripleDES.encrypt(
           combineKey(text),
           combineKey(desKey),
           option(desIv)
       );
    return encrypted.toString();
}

// 解密
export function tripleDesDecrypt(text) {
       const decrypted = CryptoJS.TripleDES.decrypt(
           text,
           combineKey(desKey),
           option(desIv)
       );
    return decrypted.toString(CryptoJS.enc.Utf8);
}

//加密
// let a = tripleDesEncrypt('http://36.134.87.77:9035')

// 解密
// let b = tripleDesDecrypt(a)

